package 
{
    import flash.errors.*;
    import flash.events.*;
    import flash.external.*;
    import flash.net.*;
    import flash.system.*;
    import flash.utils.*;

    public class SWFAddress extends Object
    {
        public static var onInit:Function;
        private static var _initializer:Boolean = _initialize();
        private static var _availability:Boolean = ExternalInterface.available;
        private static var _timer:Timer = null;
        private static var _dispatcher:EventDispatcher = new EventDispatcher();
        private static var _strict:Boolean = true;
        private static var _value:String = "";
        public static var onChange:Function;
        private static var _init:Boolean = false;
        private static var _initChange:Boolean = false;

        public function SWFAddress()
        {
            throw new IllegalOperationError("SWFAddress cannot be instantiated.");
        }

        private static function _strictCheck(param1:String, param2:Boolean) : String
        {
            if (SWFAddress.getStrict())
            {
                if (param2)
                {
                    if (param1.substr(0, 1) != "/")
                    {
                        param1 = "/" + param1;
                    }
                }
                else if (param1 == "")
                {
                    param1 = "/";
                }
            }
            return param1;
        }

        public static function getTracker() : String
        {
            return _availability ? (ExternalInterface.call("SWFAddress.getTracker") as String) : ("");
        }

        public static function hasEventListener(param1:String) : Boolean
        {
            return _dispatcher.hasEventListener(param1);
        }

        private static function _check(event:TimerEvent) : void
        {
            if ((typeof(SWFAddress["onInit"]) == "function" || _dispatcher.hasEventListener("init")) && !_init)
            {
                SWFAddress._setValueInit(_getValue());
                SWFAddress._init = true;
            }
            if (typeof(SWFAddress["onChange"]) == "function" || _dispatcher.hasEventListener("change"))
            {
                _timer.stop();
                SWFAddress._init = true;
                SWFAddress._setValueInit(_getValue());
            }
            return;
        }

        private static function _setValue(param1:String) : void
        {
            if (param1 == "undefined" || param1 == null)
            {
                param1 = "";
            }
            if (SWFAddress._value == param1 && SWFAddress._init)
            {
                return;
            }
            if (!SWFAddress._initChange)
            {
                return;
            }
            SWFAddress._value = param1;
            if (!_init)
            {
                SWFAddress._init = true;
                if (typeof(SWFAddress["onInit"]) == "function" || _dispatcher.hasEventListener("init"))
                {
                    _dispatchEvent(SWFAddressEvent.INIT);
                }
            }
            _dispatchEvent(SWFAddressEvent.CHANGE);
            return;
        }

        public static function getParameterNames() : Array
        {
            var _loc_1:String = null;
            var _loc_2:Number = NaN;
            var _loc_3:Array = null;
            var _loc_4:Array = null;
            var _loc_5:Number = NaN;
            _loc_1 = SWFAddress.getValue();
            _loc_2 = _loc_1.indexOf("?");
            _loc_3 = new Array();
            if (_loc_2 != -1)
            {
                _loc_1 = _loc_1.substr((_loc_2 + 1));
                if (_loc_1 != "" && _loc_1.indexOf("=") != -1)
                {
                    _loc_4 = _loc_1.split("&");
                    _loc_5 = 0;
                    while (_loc_5 < _loc_4.length)
                    {
                        
                        _loc_3.push(_loc_4[_loc_5].split("=")[0]);
                        _loc_5 = _loc_5 + 1;
                    }
                }
            }
            return _loc_3;
        }

        public static function setTitle(param1:String) : void
        {
            if (_availability)
            {
                ExternalInterface.call("SWFAddress.setTitle", param1);
            }
            return;
        }

        private static function _getValue() : String
        {
            var _loc_1:String = null;
            var _loc_2:String = null;
            var _loc_3:Array = null;
            _loc_2 = null;
            if (_availability)
            {
                _loc_1 = ExternalInterface.call("SWFAddress.getValue") as String;
                _loc_3 = ExternalInterface.call("SWFAddress.getIds") as Array;
                if (_loc_3 != null)
                {
                    _loc_2 = _loc_3.toString();
                }
            }
            if (_loc_2 == null || !_availability)
            {
                _loc_1 = SWFAddress._value;
            }
            else if (_loc_1 == "undefined" || _loc_1 == null)
            {
                _loc_1 = "";
            }
            return _strictCheck(_loc_1 || "", false);
        }

        public static function up() : void
        {
            var _loc_1:String = null;
            _loc_1 = SWFAddress.getPath();
            SWFAddress.setValue(_loc_1.substr(0, _loc_1.lastIndexOf("/", _loc_1.length - 2) + (_loc_1.substr((_loc_1.length - 1)) == "/" ? (1) : (0))));
            return;
        }

        public static function resetStatus() : void
        {
            if (_availability)
            {
                ExternalInterface.call("SWFAddress.resetStatus");
            }
            return;
        }

        public static function getBaseURL() : String
        {
            var _loc_1:String = null;
            _loc_1 = null;
            if (_availability)
            {
                _loc_1 = String(ExternalInterface.call("SWFAddress.getBaseURL"));
            }
            return _loc_1 == null || _loc_1 == "null" || !_availability ? ("") : (_loc_1);
        }

        public static function getTitle() : String
        {
            var _loc_1:String = null;
            _loc_1 = _availability ? (ExternalInterface.call("SWFAddress.getTitle") as String) : ("");
            if (_loc_1 == "undefined" || _loc_1 == null)
            {
                _loc_1 = "";
            }
            return _loc_1;
        }

        public static function getPath() : String
        {
            var _loc_1:String = null;
            _loc_1 = SWFAddress.getValue();
            if (_loc_1.indexOf("?") != -1)
            {
                return _loc_1.split("?")[0];
            }
            return _loc_1;
        }

        public static function href(param1:String, param2:String = "_self") : void
        {
            if (_availability && Capabilities.playerType == "ActiveX")
            {
                ExternalInterface.call("SWFAddress.href", param1, param2);
                return;
            }
            navigateToURL(new URLRequest(param1), param2);
            return;
        }

        public static function popup(param1:String, param2:String = "popup", param3:String = "\"\"", param4:String = "") : void
        {
            if (_availability && (Capabilities.playerType == "ActiveX" || ExternalInterface.call("asual.util.Browser.isSafari")))
            {
                ExternalInterface.call("SWFAddress.popup", param1, param2, param3, param4);
                return;
            }
            navigateToURL(new URLRequest("javascript:popup=window.open(\"" + param1 + "\",\"" + param2 + "\"," + param3 + ");" + param4 + ";void(0);"), "_self");
            return;
        }

        private static function _initialize() : Boolean
        {
            if (_availability)
            {
                ExternalInterface.addCallback("getSWFAddressValue", function () : String
            {
                return _value;
            }
            );
                ExternalInterface.addCallback("setSWFAddressValue", _setValue);
            }
            if (_timer == null)
            {
                _timer = new Timer(10);
                _timer.addEventListener(TimerEvent.TIMER, _check);
            }
            _timer.start();
            return true;
        }

        public static function setValue(param1:String) : void
        {
            if (param1 == "undefined" || param1 == null)
            {
                param1 = "";
            }
            param1 = _strictCheck(param1, true);
            if (SWFAddress._value == param1)
            {
                return;
            }
            SWFAddress._value = param1;
            if (_availability && SWFAddress._init)
            {
                ExternalInterface.call("SWFAddress.setValue", param1);
            }
            _dispatchEvent(SWFAddressEvent.CHANGE);
            return;
        }

        public static function getValue() : String
        {
            return _strictCheck(_value || "", false);
        }

        private static function _setValueInit(param1:String) : void
        {
            SWFAddress._value = param1;
            if (!_init)
            {
                _dispatchEvent(SWFAddressEvent.INIT);
            }
            else
            {
                _dispatchEvent(SWFAddressEvent.CHANGE);
            }
            _initChange = true;
            return;
        }

        public static function getStrict() : Boolean
        {
            var _loc_1:String = null;
            _loc_1 = null;
            if (_availability)
            {
                _loc_1 = ExternalInterface.call("SWFAddress.getStrict") as String;
            }
            return _loc_1 == null ? (_strict) : (_loc_1 == "true");
        }

        public static function dispatchEvent(event:Event) : Boolean
        {
            return _dispatcher.dispatchEvent(event);
        }

        private static function _dispatchEvent(param1:String) : void
        {
            if (_dispatcher.hasEventListener(param1))
            {
                _dispatcher.dispatchEvent(new SWFAddressEvent(param1));
            }
            param1 = param1.substr(0, 1).toUpperCase() + param1.substring(1);
            if (typeof(SWFAddress["on" + param1]) == "function")
            {
                var _loc_2:* = SWFAddress;
                _loc_2.SWFAddress["on" + param1]();
            }
            return;
        }

        public static function getQueryString() : String
        {
            var _loc_1:String = null;
            var _loc_2:Number = NaN;
            _loc_1 = SWFAddress.getValue();
            _loc_2 = _loc_1.indexOf("?");
            if (_loc_2 != -1 && _loc_2 < _loc_1.length)
            {
                return _loc_1.substr((_loc_2 + 1));
            }
            return "";
        }

        public static function forward() : void
        {
            if (_availability)
            {
                ExternalInterface.call("SWFAddress.forward");
            }
            return;
        }

        public static function removeEventListener(param1:String, param2:Function) : void
        {
            _dispatcher.removeEventListener(param1, param2, false);
            return;
        }

        public static function setStrict(param1:Boolean) : void
        {
            if (_availability)
            {
                ExternalInterface.call("SWFAddress.setStrict", param1);
            }
            _strict = param1;
            return;
        }

        public static function setHistory(param1:Boolean) : void
        {
            if (_availability)
            {
                ExternalInterface.call("SWFAddress.setHistory", param1);
            }
            return;
        }

        public static function addEventListener(param1:String, param2:Function, param3:Boolean = false, param4:int = 0, param5:Boolean = false) : void
        {
            _dispatcher.addEventListener(param1, param2, param3, param4, param5);
            return;
        }

        public static function getHistory() : Boolean
        {
            return _availability ? (ExternalInterface.call("SWFAddress.getHistory") as Boolean) : (false);
        }

        public static function back() : void
        {
            if (_availability)
            {
                ExternalInterface.call("SWFAddress.back");
            }
            return;
        }

        public static function getStatus() : String
        {
            var _loc_1:String = null;
            _loc_1 = _availability ? (ExternalInterface.call("SWFAddress.getStatus") as String) : ("");
            if (_loc_1 == "undefined" || _loc_1 == null)
            {
                _loc_1 = "";
            }
            return _loc_1;
        }

        public static function getParameter(param1:String) : String
        {
            var _loc_2:String = null;
            var _loc_3:Number = NaN;
            var _loc_4:Array = null;
            var _loc_5:Array = null;
            var _loc_6:Number = NaN;
            _loc_2 = SWFAddress.getValue();
            _loc_3 = _loc_2.indexOf("?");
            if (_loc_3 != -1)
            {
                _loc_2 = _loc_2.substr((_loc_3 + 1));
                _loc_4 = _loc_2.split("&");
                _loc_6 = _loc_4.length;
                while (_loc_6--)
                {
                    
                    _loc_5 = _loc_4[_loc_6].split("=");
                    if (_loc_5[0] == param1)
                    {
                        return _loc_5[1];
                    }
                }
            }
            return "";
        }

        public static function setStatus(param1:String) : void
        {
            if (_availability)
            {
                ExternalInterface.call("SWFAddress.setStatus", param1);
            }
            return;
        }

        public static function go(param1:int) : void
        {
            if (_availability)
            {
                ExternalInterface.call("SWFAddress.go", param1);
            }
            return;
        }

        public static function getPathNames() : Array
        {
            var _loc_1:String = null;
            var _loc_2:Array = null;
            _loc_1 = SWFAddress.getPath();
            _loc_2 = _loc_1.split("/");
            if (_loc_1.substr(0, 1) == "/" || _loc_1.length == 0)
            {
                _loc_2.splice(0, 1);
            }
            if (_loc_1.substr((_loc_1.length - 1), 1) == "/")
            {
                _loc_2.splice((_loc_2.length - 1), 1);
            }
            return _loc_2;
        }

        public static function setTracker(param1:String) : void
        {
            if (_availability)
            {
                ExternalInterface.call("SWFAddress.setTracker", param1);
            }
            return;
        }

    }
}
